﻿using System;

namespace RexToy.UI.Controls
{
    public class TableRow : Control
    {
        private TableCell[] __cells;
        public TableCell[] Cells
        {
            get { return __cells; }
        }

        internal TableRow(System.Html.DOM.Tr domRow)
        {
            __dragEventBubble = false;
            this.__domNode = new RexToy.UI.Controls.DomNode(domRow);
            this.__cells = new TableCell[0];
        }

        public TableCell GetCell(uint idx)
        {
            return this.__cells[idx];
        }

        public uint GetCellCount()
        {
            var tr = this.__domNode._element as System.Html.DOM.Tr;
            return tr.Cells.Length;
        }

        public TableCell InsertCell(uint idx)
        {
            var tr = this.__domNode._element as System.Html.DOM.Tr;
            var cellDom = tr.InsertCell(idx);
            var cell = new RexToy.UI.Controls.TableCell(cellDom);
            this.__cells.InsertAt(cell, idx);
            return cell;
        }

        public void DeleteCell(uint idx)
        {
            var tr = this.__domNode._element as System.Html.DOM.Tr;
            tr.DeleteCell(idx);
            this.__cells.RemoveAt(idx);
        }
    }
}
